package com.yidu.t299.service.lzy.impl;

import com.yidu.t299.dao.lzy.CooperateMapper;
import com.yidu.t299.domain.lzy.Cooperate;
import com.yidu.t299.service.lzy.CooperateBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
public class CooperateBizImpl implements CooperateBiz {
    @Autowired
    private CooperateMapper cooperateMapper;


    @Override
    public int deleteByPrimaryKey(Integer buddyId) {
        return cooperateMapper.deleteByPrimaryKey(buddyId);
    }

    @Override
    public int insert(Cooperate record) {
        return cooperateMapper.insert(record);
    }

    @Override
    public Cooperate selectByPrimaryKeys(Integer buddyId) {
        return cooperateMapper.selectByPrimaryKey(buddyId);
    }


    @Override
    public List<Cooperate> selectByPage(int rows, int page, String condition) {
        return cooperateMapper.selectByPage(rows, page, condition);
    }

    @Override
    public int selectCount(String condition) {
        return cooperateMapper.selectCount(condition);
    }

    @Override
    public int updateByPrimaryKey(Cooperate record) {
        return cooperateMapper.updateByPrimaryKey(record);
    }

    @Override
    public String getCondition(Cooperate record) {
        // 定义条件字符串变量，初始值为空格字符串
        String condition = " ";
        // 如果校区对象为空，则直接返回空条件字符串
        if (record == null) {
            return condition;
        }

        if (record.getBuddyId() != null) {
            condition += " and buddy_id = " + record.getBuddyId();
        }

        // 如果校区名称不为空
        if (record.getBuddyUnit() != null && record.getBuddyUnit().trim().length() != 0) {
            condition += " and buddy_unit like '%" + record.getBuddyUnit() + "%'";
        }
        System.out.println(condition);
        return condition;
    }
}
